package cn.lbd.api.designMode.proxy.dynamicproxy.crud;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Client {
    public static void main(String[] args) {
        UserServiceImpl userService=new UserServiceImpl();
        UserService proxy_service = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(), userService.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                Object value=method.invoke(userService,objects);
                String name = method.getName();
                System.out.println("【Debug】  执行了"+name+"方法");
                return value;
            }
        });
        proxy_service.add();
        proxy_service.update();
        proxy_service.delete();
        proxy_service.query();
    }
}
